﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using Platform.ObjectModel;

namespace Platform.Linq
{
	/// <summary>
	/// Realiza uma query por objetos dinâmicos
	/// </summary>
	/// <typeparam name="TElement"></typeparam>
	[Obsolete("Será removido para simplificar o código.")]
	public class DynamicQuery<TElement> : IDataObjectQueryable<TElement>
	{
		internal protected DynamicQuery( IQueryProvider provider )
			: this( null, provider )
		{ }

		internal protected DynamicQuery( Expression expression, IQueryProvider provider )
		{
			this.Expression = expression ?? Expression.Constant( this );
			this.Provider = provider;
		}

		// TODO: Propriedades que serão carregadas junto com cada entidade 
		public List<String> PropertiesToLoad
		{
			get;
			set;
		}

		#region IEnumerable<TElement> Members

		public IEnumerator<TElement> GetEnumerator()
		{
			return this.Provider.Execute<IEnumerable<TElement>>( this.Expression ).GetEnumerator();
		}

		#endregion

		#region IEnumerable Members

		System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
		{
			throw new NotImplementedException();
		}

		#endregion

		#region IQueryable Members

		public Type ElementType
		{
			get { return typeof( TElement ); }
		}

		public Expression Expression
		{
			get;
			private set;
		}

		public IQueryProvider Provider
		{
			get;
			private set;
		}

		#endregion
	}

}
